package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.domain.Wenda;
import cn.wolfcode.luowowo.article.domain.WendaContent;
import cn.wolfcode.luowowo.article.service.IWendaContentService;
import cn.wolfcode.luowowo.article.service.IWendaService;
import cn.wolfcode.luowowo.comment.domain.TravelComment;
import cn.wolfcode.luowowo.comment.domain.WendaComment;
import cn.wolfcode.luowowo.comment.query.TravelCommentQuery;
import cn.wolfcode.luowowo.comment.query.WendaCommentQuery;
import cn.wolfcode.luowowo.comment.service.IWendaCommentService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.website.annotation.UserParam;
import com.alibaba.dubbo.config.annotation.Reference;
import com.sun.net.httpserver.Authenticator;
import org.springframework.lang.UsesSunMisc;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class WendaController {
    @Reference
    private IWendaService wendaService;
    @Reference
    private IWendaContentService contentService;
    @Reference
    private IWendaCommentService wendaCommentService;

    @RequestMapping("wenda")
    //@ResponseBody
    public Object response(Model model,@UserParam UserInfo userInfo,Wenda wenda,WendaContent content){

        return "community/public";
    }




    @RequestMapping("/editComm")
    public String editComm(Model model,Long id){
        System.out.println(id);
        Wenda wenda =wendaService.queryById(id);

        model.addAttribute("wenda",wenda);

        //list
        WendaCommentQuery qo = new WendaCommentQuery();
        qo.setWendaId(id);
        qo.setCurrentPage(1);
        qo.setPageSize(100000);
        List<WendaComment> list = wendaCommentService.query(qo).getContent();
        int size = list.size( );
        model.addAttribute("size",size);
        System.out.println(list.toString() );
        model.addAttribute("list", list);


        List<WendaComment> result = wendaCommentService.queryByStatus(qo).getContent();
        model.addAttribute("count",result.size());
        model.addAttribute("result",result);

        return "community/wendaDetail";
    }


    @RequestMapping("/responseAdd")
    public String responseAdd(Model model,WendaComment comment,@UserParam UserInfo user) {
        System.out.println(user);
        //c
        comment.setUserId(user.getId());
        comment.setHeadUrl(user.getHeadImgUrl());
        comment.setLevel(user.getLevel());
        comment.setUsername(user.getNickname());
        comment.setCreateTime(new Date());
        System.out.println(comment+"12");
        WendaComment wendaComment = wendaCommentService.save(comment);
        model.addAttribute("c", wendaComment);
        //floor
        model.addAttribute("floor", wendaCommentService.getCount(comment.getWendaId()));
        return "community/commentTpl";
    }


}
